package cz.zcu.fav.rat.security.beans;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import cz.zcu.fav.rat.security.service.LoginImplementor;

public class UserDetailsBean implements UserDetails
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Integer id;
	private String userName;
	private String password;
	private Collection<? extends GrantedAuthority> authorities;
	private String implementor;

	public String getImplementor()
	{
		return implementor;
	}

	public void setImplementor(String implementor)
	{
		this.implementor = implementor;
	}

	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities()
	{
		return authorities;
	}

	@Override
	public String getPassword()
	{
		return password;
	}

	@Override
	public String getUsername()
	{
		return userName;
	}

	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	@Override
	public boolean isAccountNonExpired()
	{
		return true;
	}

	@Override
	public boolean isAccountNonLocked()
	{
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired()
	{
		return true;
	}

	@Override
	public boolean isEnabled()
	{
		return true;
	}

	public void setAuthorities(List<String> roles)
	{
		List<GrantedAuthority> listOfAuthorities = new ArrayList<GrantedAuthority>();
		for (String role : roles)
		{
			listOfAuthorities.add(new SimpleGrantedAuthority(role));
		}
		authorities = listOfAuthorities;
	}

}